#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5e4+10;

typedef long long ll;

int primenum,prime[MAXN],mu[MAXN],smu[MAXN];
ll cal[MAXN];
bool np[MAXN];

ll calc(int x){
	ll res = 0;
	for(int l = 1,r;l <= x;l=r+1){
		r = min(x,x/(x/l));
		res = res + (r-l+1) * (x/l);
	}
	return res;
}

void init(){
	for(int i = 2;i < MAXN;i++){
		if(!np[i]){
			prime[++primenum] = i;
			mu[i] = -1;
		}
		for(int j = 1;j <= primenum &&prime[j] * i < MAXN;j++){
			np[i * prime[j]] = 1;
			mu[i * prime[j]] = -mu[i];
			if(i % prime[j] == 0){
				mu[i * prime[j]] = 0;
				break;
			}
		}
	}
	mu[1] = 1;
	for(int i = 1;i < MAXN;i++) smu[i] = smu[i-1] + mu[i];
	for(int i = 1;i < MAXN;i++) cal[i] = calc(i);
}

int main(){
	init();
	int T;scanf("%d",&T);
	while(T--){
		int n,m; scanf("%d %d",&n,&m);
		ll ans = 0;
		for(int l = 1,r;l <= min(n,m);l=r+1){
			r = min(n,min(m,min(n/(n/l),m/(m/l))));
			ans = ans + (smu[r] - smu[l-1]) * cal[n/l] * cal[m/l];
		}
		printf("%lld\n",ans);
	}
	return 0;
}
